package views.mediators {
	
	import com.axon.mvc.helpers.AxVerbs;
	import com.axon.mvc.patterns.mediator.AxMediator;
	
	import models.vo.User;
	
	import views.components.LoungeStatusTopRightView;
	
	/**
	 * Coordinate user authentication.
	 */
	public class LoungeStatusTopRightMediator extends AxMediator 
	{
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function LoungeStatusTopRightMediator(viewComponent: LoungeStatusTopRightView) { super(viewComponent); }
			
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		private function get view(): LoungeStatusTopRightView { return this.viewComponent as LoungeStatusTopRightView; }
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		override protected function initialize(): void
		{
			regResponseInterest( null, [ AxVerbs.LOGIN, AxVerbs.LOGOUT ] );
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function eventLoginToggle(): void
		{
			if ( !(facade as AppFacade).sessionProxy.somebodyConnected() )
				callController(null, AxVerbs.LOGIN_POPUP);
			else
				callController(null, AxVerbs.LOGOUT);	
		}
		
		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function respLoginSuccess(sender: Object, body: Object, extraInfo: Object): void
		{
			view.lbLoginLogout.label 	= "Logout";
			view.txtUsername.text		= User(body).name;
			view.hBoxUser.visible  		= true;
			view.lbRefresh.visible 		= true;	
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function respLoginFailure(sender: Object, body: Object, extraInfo: Object): void
		{
		    view.errorString = "Conta de usuário e/ou senha inválidos.";
		}

		//////////////////////////////////////////////////////////////////////////////////////////////////////
		
		public function respLogoutSuccess(sender: Object, body: Object, extraInfo: Object): void
		{
			view.lbLoginLogout.label	= "Login";
			view.txtUsername.text		= "";
			view.hBoxUser.visible		= false;
			view.lbRefresh.visible		= false;	
		}

	}
}